package com.briup.jd2407cms.web.controller;

import com.briup.jd2407cms.domain.Article;
import com.briup.jd2407cms.result.Result;
import com.briup.jd2407cms.service.ArticleService;
import com.briup.jd2407cms.vo.ArticleSelectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Api(tags = "资讯管理")
@RestController
@RequestMapping("/auth/article")
public class ArticleController {

    @Autowired
    ArticleService articleService;

    @ApiOperation("新增或修改文章")
    @PostMapping("/saveOrUpdate")
    public Result<?> addOrEditArticle(@RequestBody Article article){
        articleService.saveOrUpdateArticle(article);
        return article.getId()==null?Result.success("新增成功"):Result.success("修改成功");
    }

    @ApiOperation("审核文章")
    @PutMapping("/review")
    public Result<?> reviewArticle(@RequestParam Long id,
                                   @RequestParam String status){
        articleService.changeArticleStatus(id,status);
        return Result.success(status);
    }

    @ApiOperation("（批量）删除文章")
    @DeleteMapping("/deleteByBatch/{ids}")
    public Result<?> removeArticleBatch(@PathVariable List<String> ids){
        return Result.success();
    }

    @ApiOperation("根据id查询文章详情")
    @GetMapping("/queryById/{id}")
    public Result<?> findArticleById(@PathVariable Long id){
        return Result.success(articleService.getArticleDetailById(id));
    }

    @ApiOperation("分页按条件查询多个文章")
    @PostMapping("/query")
    public Result<?> findManyArticlesByConditionByPage(@RequestBody ArticleSelectVo articleVo){
        return Result.success(articleService.getAllByConditionByPage(articleVo.getPageNum(),
                articleVo.getPageSize(), articleVo.getName(), articleVo.getStatus(), articleVo.getCategoryId(),
                articleVo.getUserId(), articleVo.getCharged(), articleVo.getBegin(), articleVo.getEnd()));
    }
}
